package com.atguigu.jxc.service.impl;

import com.atguigu.jxc.dao.DamageListDao;
import com.atguigu.jxc.dao.DamageListGoodsDao;
import com.atguigu.jxc.dao.UserDao;
import com.atguigu.jxc.entity.DamageList;
import com.atguigu.jxc.entity.DamageListGoods;
import com.atguigu.jxc.entity.User;
import com.atguigu.jxc.service.DamageListService;
import com.atguigu.jxc.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.servlet.http.HttpSession;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

@Service
public class DanageListServiceImpl implements DamageListService {


    @Autowired
    private DamageListDao damageListDao;

    @Autowired
    private DamageListGoodsDao damageListGoodsDao;

    /**
     * 报损单保存
     * @param damageList
     * @return
     */
    @Override
    @Transactional
    public int save(DamageList damageList) {
        //保存报损单
        int save = damageListDao.save(damageList);

        //获取 damage_list_id
        String damageListId = damageList.getDamageListId();

        //保存报损单 关联的商品列表
        List<DamageListGoods> damageListGoods = damageList.getDamageListGoods();

        //遍历插入 报损单关联的商品
        for (DamageListGoods goods : damageListGoods){
            goods.setDamageListId(Integer.parseInt(damageListId));
            int save1 = damageListGoodsDao.save(goods);
        }
        return save;
    }


    @Override
    public List<DamageList> getListByDate(String sTime, String eTime) {
        return damageListDao.getListByDate(sTime,eTime);
    }

    @Override
    public List<DamageListGoods> getByListId(Integer damageListId) {
        return damageListGoodsDao.getByListId(damageListId);
    }
}
